﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Leo.BL;
using Leo.Entities;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace VeterinariaDrLeo.Controllers
{
    public class ClienteController : Controller
    {
        //
        // GET: /Cliente/

        [Dependency]
        public IClienteBL ClienteBL { get; set; }

        public ActionResult Index()
        {
            var listaCliente = ClienteBL.GetAllFromCliente();
            return View(listaCliente);
        }

        [HttpPost]
        public ActionResult Index(string criterio = "")
        {
            var listaCliente = ClienteBL.GetFromClienteByCriterio(criterio);
            return View(listaCliente);
        }

        public ActionResult Create()
        {
            var cliente = ClienteBL.GetAllFromCliente();
            
            return View();
        }

        [HttpPost]
        public ActionResult Create(Cliente cliente)
        {
            ClienteBL.AddCliente(cliente);
            return RedirectToAction("index");

        }

        public ActionResult Edit(int id)
        {
            var Editar = ClienteBL.GetFromClienteById(id);
            return View(Editar);

        }

        [HttpPost]
        public ActionResult Edit(int id, Cliente cliente)
        {
               ClienteBL.UpdateCliente(cliente);
                return RedirectToAction("index");
           
        }

        public ActionResult Delete(int id)
        {
            ClienteBL.RemoveCliente(id);
            return RedirectToAction("index");
        }

     

    }
}
